package com.project.entity.sys;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.project.dao.annotation.Like;

/**
 * 系统角色
 * @author
 */
@Entity
@Table(name="S_ROLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DynamicInsert
@DynamicUpdate
public class Role extends BaseEntity implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Column(name = "role_code", length = 20)
	private String roleCode;//角色code
	@Column(name = "role_name", length = 50)
	@Like
	private String roleName;//角色名称
	@Column(name = "status", length = 1)
	private String status;//是否启用（0：不启用；1：启用）
	@Column(name = "rmk", length = 200)
	private String rmk;//备注
	@Column(name = "create_user", length = 20)
	private String createUser;//创建人
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time", length = 19)
	private Date createTime;//创建时间
	@Column(name = "update_user", length = 20)
	private String updateUser;//修改人
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_time", length = 19)
	private Date updateTime;//修改时间
	
	@ManyToMany
    @JoinTable(name="S_USER_ROLE", 
    		joinColumns = { @JoinColumn(name = "ROLE_ID",nullable = false) }, 
    		inverseJoinColumns = { @JoinColumn(name = "USER_ID",nullable = false) },
    		uniqueConstraints = {@UniqueConstraint(columnNames={"USER_ID","ROLE_ID"})})
	List<User> users = new ArrayList<User>();//该角色下的用户
	
	@ManyToMany
	@JoinTable(name="S_ROLE_PERMISSIONS", 
    		joinColumns = { @JoinColumn(name = "ROLE_ID",nullable = false) }, 
    		inverseJoinColumns = { @JoinColumn(name = "PERMISSIONS_ID",nullable = false) },
    		uniqueConstraints = {@UniqueConstraint(columnNames={"ROLE_ID","PERMISSIONS_ID"})})
	List<Permissions> permissions = new ArrayList<Permissions>();//角色所拥有的权限
	
	public String getRoleCode() {
		return roleCode;
	}
	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}
	
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	
	public String getRmk() {
		return rmk;
	}
	public void setRmk(String rmk) {
		this.rmk = rmk;
	}
	
	public String getCreateUser() {
		return createUser;
	}
	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}
	
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public String getUpdateUser() {
		return updateUser;
	}
	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}
	
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	public List<User> getUsers() {
		return users;
	}
	public void setUsers(List<User> users) {
		this.users = users;
	}
	
	public List<Permissions> getPermissions() {
		return permissions;
	}
	public void setPermissions(List<Permissions> permissions) {
		this.permissions = permissions;
	}
	
	
	
	
}
